package co.fitstart.mobile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.user.Student;
import co.fitstart.entity.user.StudentTargetData;
import co.fitstart.mobile.dao.support.StudentDaoSupport;
import co.fitstart.mobile.service.StudentService;

/**
 *
 * @author Ark
 *
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    @Autowired
    private StudentDaoSupport studentDaoSupport;
    
    /* (non-Javadoc)
     * @see co.fitstart.mobile.service.StudentService#listStudentTargetData(co.fitstart.entity.user.Student, co.fitstart.entity.course.round.CourseRound)
     */
    public List<StudentTargetData> listStudentTargetData(Student student, CourseRound courseRound) {
        return studentDaoSupport.listStudentTargetData(student, courseRound);
    }

    /* (non-Javadoc)
     * @see co.fitstart.mobile.service.StudentService#create(co.fitstart.entity.user.StudentTargetData)
     */
    public void create(StudentTargetData data) {
        genericDaoSupport.save(data);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.mobile.service.StudentService#loadLatestStudentTargetData(co.fitstart.entity.user.Student, co.fitstart.entity.course.round.CourseRound)
     */
    public StudentTargetData loadLatestStudentTargetData(Student student, CourseRound courseRound) {
        List<StudentTargetData> targets = studentDaoSupport.listStudentTargetData(student, courseRound);
        
        return targets.isEmpty() ? null : targets.get(0);
    }
}
